$.ajax({
    type: "POST",
    url: "/api/userpl",
    success:(data)=>{
        console.log(data)
        const obj = data.data
        $(".h3pl").text(`评论 (${obj.length})`)
        for(let i=0;i<obj.length;i++){
            $(".tll").append(`
            <li class="comment rounded">
                <div class="thumb">
                    <img src=${obj[i].img} style="height:70px;width:70px;border-radius: 50%;">
                </div>
                <div class="details">
                <h4 class="name"><a href="#">${obj[i].name}</a></h4>
                <span class="date">${obj[i].data}</span>
                <p>${obj[i].text}</p>
                <a class="btn btn-default btn-sm hf">回复</a>
                </div>
            </li>
        `)
        }
    }
})
$(".fb").on("click",()=>{
    const text = $(".txt").val()
    const myDate = new Date()
    const time = myDate.toLocaleString()
    console.log(text)
    $.ajax({
        type:"POST",
        url:"/api/userpl/add",
        data:{
            name:vid,
            sculpture:1,
            text:text,
            img:vimg,
            data:time,
            email:3,
        },
        success:(data)=>{
            if(data.data==="you dont have any token to access the api"){
                alert("请登录后评论")
                window.location.href='http://localhost:3300/contact.html'
            }else{
                alert("评论成功")
                console.log(data)
                window.location.reload()
            }
        }
    })
})
$(".tll").on("click", function (e) {
    const text = $(".txt").val()
    const myDate = new Date()
    const time = myDate.toLocaleString()
    if ($(e.target).text() == "回复") {
        $(".tll").append(`
            <li class="comment child rounded">
                <div class="thumb">
                    <img src=${vimg} style="height:60px;width:60px;border-radius: 50%;">
                </div>
                <div class="details">
                <h4 class="name"><a href="#">${vid}</a></h4>
                <span class="date">${time}</span>
                <p>${text}</p>
                <a class="btn btn-default btn-sm">回复</a>
                </div>
            </li>
        `)
    }
})
